package com.moji.controller.api;

import com.moji.common.base.ApiResult;
import com.moji.entity.dto.ReqLoginDto;
import com.moji.entity.dto.ReqLogoutDto;
import com.moji.service.SystemService;
import com.moji.util.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description
 * @Author ccl
 * @Version 1.0
 **/
@CrossOrigin
@RestController
@RequestMapping("api")
@Api(tags = "系统登录退出基本信息接口", value = "系统登录退出基本信息接口")
public class SystemController {

    @Resource
    private SystemService systemService;

    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("login")
    @ApiOperation("登录系统")
    public ApiResult login(@RequestBody ReqLoginDto loginReqDao){
        return systemService.login(loginReqDao);
    }

    @PostMapping("logout")
    @ApiOperation("退出系统")
    public ApiResult logout(@RequestBody ReqLogoutDto reqLogoutDao, HttpServletRequest request){
        String loginId = reqLogoutDao.getLoginId();
        systemService.logout(loginId,request);
        return ApiResult.ok(ResultCode.SUCCESS);
    }
}
